package plgdb

import (
	"dgo/MyProj/PrjDBUtils"
	"gitee.com/ymofen/supervalue"
)

type PlgDBUpdateParam struct {
	HttpReq      *PlgDBRequest
	ResID        string
	DataSourceid string
	DBName       string
	SingleName   string
	Req          *wrapper.SuperValue
	Resp         *wrapper.SuperValue
	DBResConf    *wrapper.SuperValue
	Args         *wrapper.SuperValue
	Dao          *PrjDBUtils.DAOHelper

	// 需要更新的数据
	Data                                                     *wrapper.SuperValue
	UpConf                                                   *wrapper.SuperValue
	trans                                                    bool
	err_sql                                                  string
	tracesql                                                 int
	table, keyfields, ignoreupdatefields, ignoreinsertfields string
	uptype                                                   int
	batchupflag                                              int
	InsertIfEmpty                                            string

	GetParamValFunc func(sender interface{}, key string) (bool, interface{})
}

func NewDBUpdateParma() *PlgDBUpdateParam {
	rval := &PlgDBUpdateParam{}
	return rval
}

func (this *PlgDBUpdateParam) Close() error {
	if this.Dao != nil {
		this.Dao.Close()
		this.Dao = nil
	}
	return nil
}

func (this *PlgDBUpdateParam) GetParamVal(key string) (ok bool, val interface{}) {
	ok = false
	if this.HttpReq.OnGetParamValFunc != nil {
		ok, val = this.HttpReq.OnGetParamValFunc(this, key)
	}
	if !ok && this.GetParamValFunc != nil {
		ok, val = this.GetParamValFunc(this, key)
	}

	return
}

func (this *PlgDBUpdateParam) ReqStringByName(key string, def string) string {
	if this.Req == nil {
		return def
	}
	return this.Req.StringByName(key, def)
}

func (this *PlgDBUpdateParam) ReqIntByName(key string, def int) int {
	if this.Req == nil {
		return def
	}
	return this.Req.IntByName(key, def)
}
